<script>
	import Vue from 'vue'
	import {
		wxAuthorize
	} from '@/utils/auth.js';
	export default {
		// 此处globalData为了演示其作用，不是uView框架的一部分
		globalData: {
			searchText: '',
			userinfo: null
		},
		created() {
			console.log("App created")
			let that = this
			//在页面加载时读取Storage里的状态信息
			/**
			 * 设置页面风格
			 */
			let skin = uni.getStorageSync('skin');
			if (skin != null && skin != undefined && skin != "") {
				//
				/**
				 * 设置主题颜色
				 */
				// 主题色
				that.$u.vuex('vuex_themeColor', skin.themeColor);
				// 各个栏目标题配色 ex: 活动产品 人员推荐 等
				that.$u.vuex('vuex_titleColor', skin.textColor);
				// 文字主色
				that.$u.vuex('vuex_textColor', skin.textColor);
				// 底部菜单 选中颜色
				that.$u.vuex('vuex_tabbarActiveColor', skin.tabbarActiveColor);
				//导航背景颜色
				that.$u.vuex('vuex_navBackground.backgroundColor', skin.navBackgroundColor);
			}
			/**
			 * 设置语言
			 */
			let lang = uni.getStorageSync('lang');
			if (lang != null && lang != undefined && lang != "") {
				that.$i18n.locale = lang;
				that.$u.vuex('vuex_tabbar', that.$t('tabbar'));
				that.$u.vuex('vuex_lang', lang);
			}
			/**
			 * 全局设置屏幕宽度
			 */
			uni.getSystemInfo({
				success: function(res) {
					that.$u.vuex('vuex_windowWidth', res.windowWidth);
				}
			});
			/**
			 * 监听窗口尺寸变化
			 */
			uni.onWindowResize((res) => {
				that.$u.vuex('vuex_windowWidth', res.size.windowWidth);
			})
		},
		onResize() {
			let _this = this
			uni.getSystemInfo({
				success: function(res) {
					console.log(res.windowWidth);
					if (res.windowWidth > res.windowHeight) {
						// 横屏
						_this.isLandScape = true
					} else {
						// 竖屏
						_this.isLandScape = false
					}
				}
			})
		},
		onLaunch: function() {
			console.log("App onLaunch")
			let _this = this;
			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif

					// #ifdef MP-WEIXIN || MP-QQ
					Vue.prototype.StatusBar = e.statusBarHeight;
					let capsule = wx.getMenuButtonBoundingClientRect();
					if (capsule) {
						Vue.prototype.Custom = capsule;
						// Vue.prototype.capsuleSafe = uni.upx2px(750) - capsule.left + uni.upx2px(750) - capsule.right;
						Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					}
					// #endif		


					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			})

			// #ifdef H5
			//判断是否是微信浏览器
			_this.$u.vuex('vuex_isWechat', _this.$u.wx.isWechat());
			// 记录进入app时的url IOS获取签名时使用
			if (typeof window.entryUrl === 'undefined' || window.entryUrl === '') {
				window.entryUrl = location.href.split('#')[0]
			}
			//获取微信授权
			_this.$u.wx.wxOauth()
			// #endif
		},
		onShow: function() {
			console.log("App onShow")
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			goHomeOrGoGuide() {
				if (!this.vuex_guide) {
					// app 直接跳转会存在闪的问题
					// uni.reLaunch({
					// 	url: '/pages/guide/guide'
					// });
					setTimeout(function() {
						uni.navigateTo({
							url: '/pages/guide/guide'
						});
					}, 1000)
				}
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */

	/*
	 * 需放置再style标签内容的最前面
	 */
	@import "common/css/iconfont.css";
	@import "uview-ui/index.scss";
	@import "colorui/main.css";
	@import "colorui/icon.css";
	@import "common/css/uni-ui.scss";
	@import "common/css/theme.scss";
	body{overflow-x: hidden;}
</style>
